package com.orhonit.ipb.portal.configuration;

import javax.servlet.MultipartConfigElement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration  
public class UploadFileConfiguration extends WebMvcConfigurerAdapter{  
  
	@Autowired
	private UploadConfigTemp uploadConfig;
    @Bean  
    public MultipartConfigElement multipartConfigElement() {  
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        factory.setMaxFileSize("5MB");  
        factory.setMaxRequestSize("5MB");  
        return factory.createMultipartConfig();  
    }  
    
    /**
     * @Description: 对文件的路径进行配置,创建一个虚拟路径/Path/** ，即只要在<img src="/Path/picName.jpg" />便可以直接引用图片
     *这是图片的物理路径  "file:/+本地图片的地址"
     * @Date： Create in 14:08 2017/12/20
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {   
       registry.addResourceHandler("/Path/**").addResourceLocations("file:/"+uploadConfig.getPath());
        super.addResourceHandlers(registry);
    }
    
}  